<template>
    <div class="fav">
        <span v-if="isFavorate" @click="unfavorite(id)">取消收藏</span><span v-else @click="favorite(id)">收藏</span>
    </div>
</template>

<script>
    export default {
        name: "fav",
        data(){
            return {isFavorate:true}
        },
        props:["id","isfav"],
        mounted(){
            this.isFavorate=this.isfav;
        },
        methods:{
            favorite(id){
                axios.get("/post/favorite/"+id).then(res=>{
                    this.isFavorate=true;
                })
            },
            unfavorite(id){
                axios.get("/post/unfavorite/"+id).then(res=>{
                    this.isFavorate=false;
                })
            }
        }

    }
</script>

<style scoped>

.fav span{
    cursor: pointer;
}

</style>